import React, {Component} from 'react';
import { Carousel } from 'antd';
import './index.less'
import SwiperItem from "./SwiperItem";
import {getBanner} from "../../network/banner";

class Swiper extends Component {
    state = {
        banners: []
    }

    render() {
        return (
            <div className='banner'>
                <Carousel autoplay>
                    {
                        this.state.banners.map(item => {
                            return <SwiperItem key={item.bid} imgSrc={item.burl}/>
                        })
                    }
                </Carousel>
            </div>
        );
    }

    async componentDidMount() {
        const result = await getBanner();
        if(result.code === 200){
            this.setState({
                banners: result.data
            })
        }
    }
}

export default Swiper;